import { getAdoptForAccountList } from '@/services/api/api-county';
import { DrawerForm, ModalForm, ProFormTextArea } from '@ant-design/pro-form';
import ProList from '@ant-design/pro-list';
import { ActionType } from '@ant-design/pro-table';
import { Badge, Tag, Typography } from 'antd';
import React, { useRef } from 'react';
import { useAccess } from 'umi';
import DetailsArticleAdoptInstructAccount from './DetailsArticleAdoptInstructAccount';

interface DetailsArticleAdoptProps {
  type: number;
  articleId: string | undefined;
  count: number | undefined;
  onRefurbish: () => void;
  countyKey:string
}

const DetailsArticleAdopt: React.FC<DetailsArticleAdoptProps> = ({
  type,
  articleId,
  count,
  onRefurbish,
  countyKey
}) => {
  const access = useAccess();
  const actionRef = useRef<ActionType>();

  /**
   * 请求网络
   * @param value
   */
  const request = async (params = {}) => {
    const response = await getAdoptForAccountList({ articleId,countyKey });
    return Promise.resolve({
      data: response.data,
      total: response.data.length,
      success: response.code === 0,
    });
  };

  return (
    <DrawerForm
      key="details_adopt_drawer_form"
      title="收录详情"
      drawerProps={{
        // maskClosable: false,
        destroyOnClose: true,
      }}
      trigger={
        <a>
          <Badge
            count={count}
            style={{
              marginBlockStart: -5,
              marginInlineStart: 4,
              color: '#1890FF',
              backgroundColor: '#E6F7FF',
            }}
          />
          点击查看
        </a>
      }
      onVisibleChange={(visible) => {
        if (visible) {
        }
      }}
      submitter={false}
    // submitter={
    //   access.线索上报x选题计划x配置x管理员 && {
    //     searchConfig: {
    //       submitText: false,
    //       resetText: false,
    //     },
    //     render: (props, defaultDoms) => {
    //       return [
    //         ...defaultDoms,
    //         <DetailsArticleAdoptInstructAccount
    //           key="details_adopt_assign_account"
    //           articleId={articleId}
    //           type={type}
    //           onRefurbish={function (): void {
    //             actionRef.current?.reload();
    //             onRefurbish();
    //           }}
    //         />,
    //       ];
    //     },
    //   }
    // }
    >
      <ProList<CountyData.AdoptForAccountVo>
        rowKey="name"
        ghost
        request={request}
        actionRef={actionRef}
        headerTitle={
          <DetailsArticleAdoptInstructAccount
            key="details_adopt_assign_account"
            articleId={articleId}
            type={type}
            onRefurbish={function (): void {
              actionRef.current?.reload();
              onRefurbish();
            }}
            countyKey={countyKey}
          />
        }
        metas={{
          title: {
            dataIndex: 'organizationName',
            render(dom, entity, index, action, schema) {
              return (
                <>
                  <Typography.Title level={5}>
                    {entity.isInstruct === 0 && entity.cancelAccountId && <Tag color='red'>
                      取消
                    </Tag>}
                    <Tag color={entity.isInstruct === 0 ? 'green' : 'orange'}>
                      {entity.isInstruct === 0 ? '自主' : '指令'}
                    </Tag>
                    {entity.organizationName} - {entity.accountName}
                  </Typography.Title>
                </>
              );
            },
          },
          description: {
            dataIndex: 'createdTime',
            render(dom, entity, index, action, schema) {
              return (
                <Typography.Paragraph>
                  {/* {entity.isInstruct === 1 && (
                    <blockquote>指令人：{entity.instructAccountName}</blockquote>
                  )}
                  {entity.instructDescribes != null && entity.instructDescribes != "" && (
                    <blockquote>指令描述：{entity.instructDescribes}</blockquote>
                  )}
                  <blockquote>收录时间：{entity.createdTime}</blockquote>

                  {entity.isInstruct === 0 && entity.cancelAccountId && (
                    <><blockquote>取消人：{entity.cancelAccountName}</blockquote>
                      <blockquote>取消时间：{entity.cancelTime}</blockquote>
                      <blockquote>取消描述：{entity.cancelDescribes}</blockquote></>
                  )} */}
                </Typography.Paragraph>
              );
            },
          },
        
        }}
      />
    </DrawerForm >
  );
};

export default DetailsArticleAdopt;
